package hr.ctg.domain.model;

// Generated 2007.05.02 22:50:59 by Hibernate Tools 3.2.0.b9

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
 * Osobina generated by hbm2java
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "osobina", uniqueConstraints = @UniqueConstraint(columnNames = { "naziv" }))
@NamedQueries( {
		@NamedQuery(name = "Osobina.findAll", query = "select oa from Osobina oa order by oa.naziv"),
		@NamedQuery(name = "Osobina.findByIdObjekta", query = "select o from Osobina o join o.objekts ob where ob.idObjekta=?"),
		@NamedQuery(name = "Osobina.findByIdTipaObjekta", query = "select o from Osobina o join o.tipObjektas to where to.idTipaObjekta=?"),
		@NamedQuery(name = "Osobina.findByIdTipaosobineIdObjekta", query = "select distinct os from Osobina os join os.objekts o where os.tipOsobine.idTipaOsobine = ? and o.idObjekta=?") })
public class Osobina implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2562665439320065125L;
	private int idOsobine;
	private String naziv;
	private TipOsobine tipOsobine;
	private Set<Objekt> objekts = new HashSet<Objekt>(0);
	private Set<TipObjekta> tipObjektas = new HashSet<TipObjekta>(0);

	public Osobina() {
	}

	public Osobina(final int idOsobine, final String naziv) {
		this.idOsobine = idOsobine;
		this.naziv = naziv;
	}
	
	public Osobina(final int idOsobine) {
		this.idOsobine = idOsobine;
	}	

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Osobina)) {
			return false;
		}
		final Osobina other = (Osobina) obj;
		if (idOsobine != other.getIdOsobine()) {
			return false;
		}
		return true;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_osobine", unique = true, nullable = false)
	@NotNull
	public int getIdOsobine() {
		return idOsobine;
	}

	@Column(name = "naziv", unique = true, nullable = false, length = 50)
	@NotNull
	@Length(max = 50)
	public String getNaziv() {
		return naziv;
	}

	public void setIdOsobine(final int idOsobine) {
		this.idOsobine = idOsobine;
	}

	public void setNaziv(final String naziv) {
		this.naziv = naziv;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "osobina_objekta", inverseJoinColumns = @JoinColumn(name = "id_objekta", referencedColumnName = "id_objekta"), joinColumns = @JoinColumn(name = "id_osobine", referencedColumnName = "id_osobine"))
	public Set<Objekt> getObjekts() {
		return objekts;
	}

	public void setObjekts(final Set<Objekt> objekts) {
		this.objekts = objekts;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "osobina_tip_objekta", inverseJoinColumns = @JoinColumn(name = "id_tipa_objekta", referencedColumnName = "id_tipa_objekta"), joinColumns = @JoinColumn(name = "id_osobine", referencedColumnName = "id_osobine"))
	public Set<TipObjekta> getTipObjektas() {
		return tipObjektas;
	}

	public void setTipObjektas(final Set<TipObjekta> tipObjektas) {
		this.tipObjektas = tipObjektas;
	}

	public void setTipOsobine(final TipOsobine tipOsobine) {
		this.tipOsobine = tipOsobine;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_tipa_osobine", nullable = false)
	@NotNull
	public TipOsobine getTipOsobine() {
		return tipOsobine;
	}
}
